#include "stdafx.h"
#include "PrimitiveGeometry.h"

GraphicComponent* createTriangle(Render* render, float size)
{
	assert(size > 0);
	GraphicComponent* gComponent = new GraphicComponent(render);
	Vertex* vert = new Vertex[3];	// vertex array
	float z = 0.5f;
	vert[0].pos[0] = 0.0f; vert[0].pos[1] = size; vert[0].pos[2] = z;
	vert[1].pos[0] = -size;vert[1].pos[1] = -size;vert[1].pos[2] = z;
	vert[2].pos[0] = size; vert[2].pos[1] = -size;vert[2].pos[2] = z;

	VertexDesc desc;
	desc.sizeofVertex = sizeof(Vertex);
	gComponent->createVertexShader("default.hlsl", "VSMain", desc);
	gComponent->createPixelShader("default.hlsl", "PSMain");
	gComponent->createVertexBuffer(vert, 3, desc.sizeofVertex);
	delete [] vert;

	unsigned int indices[] = { 0, 1, 2 };
	gComponent->createIndexBuffer(indices, 3);


	return gComponent;
}


GraphicComponent* createCube(Render* render, float size)
{
	assert(size > 0);
	GraphicComponent* gComponent = new GraphicComponent(render);
	Vertex* vert = new Vertex[8];	// vertex array
	vert[0].pos[0] = -size; vert[0].pos[1] = size;  vert[0].pos[2] = size;
	vert[1].pos[0] = -size; vert[1].pos[1] = -size; vert[1].pos[2] = size;
	vert[2].pos[0] = size;  vert[2].pos[1] = -size; vert[2].pos[2] = size;
	vert[3].pos[0] = size;  vert[3].pos[1] = size;  vert[3].pos[2] = size;
	vert[4].pos[0] = -size; vert[4].pos[1] = size;  vert[4].pos[2] = -size;
	vert[5].pos[0] = -size; vert[5].pos[1] = -size; vert[5].pos[2] = -size;
	vert[6].pos[0] = size;  vert[6].pos[1] = -size; vert[6].pos[2] = -size;
	vert[7].pos[0] = size;  vert[7].pos[1] = size;  vert[7].pos[2] = -size;

	VertexDesc desc;
	desc.sizeofVertex = sizeof(Vertex);
	gComponent->createVertexShader("default.hlsl", "VSMain", desc);
	gComponent->createPixelShader("default.hlsl", "PSMain");
	gComponent->createVertexBuffer(vert, 8, desc.sizeofVertex);
	delete [] vert;

	//                         ---up-------  ---right----  ---front----  ---left-----  ---back-----  ---bottom---
	unsigned int indices[] = { 0,1,2, 1,2,3, 2,3,7, 6,2,7, 3,0,7, 0,4,7, 5,1,0, 5,0,4, 2,1,5, 2,5,6, 6,5,4, 6,4,7  };
	gComponent->createIndexBuffer(indices, 36);

	return gComponent;
}